<?xml version="1.0" encoding="ascii"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
          "DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>plugins.timewarning</title>
  <link rel="stylesheet" href="epydoc.css" type="text/css" />
  <script type="text/javascript" src="epydoc.js"></script>
</head>

<body bgcolor="white" text="black" link="blue" vlink="#204080"
      alink="#204080">
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="http://openttd-python.googlecode.com">OpenTTD-Python</a></th>
          </tr></table></th>
  </tr>
</table>
<table width="100%" cellpadding="0" cellspacing="0">
  <tr valign="top">
    <td width="100%">
      <span class="breadcrumbs">
        <a href="plugins-module.html">Package&nbsp;plugins</a> ::
        Module&nbsp;timewarning
      </span>
    </td>
    <td>
      <table cellpadding="0" cellspacing="0">
        <!-- hide/show private -->
        <tr><td align="right"><span class="options">[<a href="javascript:void(0);" class="privatelink"
    onclick="toggle_private();">hide&nbsp;private</a>]</span></td></tr>
        <tr><td align="right"><span class="options"
            >[<a href="frames.html" target="_top">frames</a
            >]&nbsp;|&nbsp;<a href="plugins.timewarning-pysrc.html"
            target="_top">no&nbsp;frames</a>]</span></td></tr>
      </table>
    </td>
  </tr>
</table>
<h1 class="epydoc">Source Code for <a href="plugins.timewarning-module.html">Module plugins.timewarning</a></h1>
<pre class="py-src">
<a name="L1"></a><tt class="py-lineno"> 1</tt>  <tt class="py-line"><tt class="py-comment"># code by RoRTom, conversion to plugin by yorick</tt> </tt>
<a name="L2"></a><tt class="py-lineno"> 2</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt id="link-0" class="py-name" targets="Module plugins.pluginclass=plugins.pluginclass-module.html"><a title="plugins.pluginclass" class="py-name" href="#" onclick="return doclink('link-0', 'pluginclass', 'link-0');">pluginclass</a></tt> </tt>
<a name="L3"></a><tt class="py-lineno"> 3</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-1" class="py-name" targets="Module ottd_config=ottd_config-module.html"><a title="ottd_config" class="py-name" href="#" onclick="return doclink('link-1', 'ottd_config', 'link-1');">ottd_config</a></tt> <tt class="py-keyword">import</tt> <tt id="link-2" class="py-name" targets="Variable ottd_client_event.config=ottd_client_event-module.html#config,Variable ottd_config.config=ottd_config-module.html#config,Variable plugins.stats.config=plugins.stats-module.html#config"><a title="ottd_client_event.config
ottd_config.config
plugins.stats.config" class="py-name" href="#" onclick="return doclink('link-2', 'config', 'link-2');">config</a></tt><tt class="py-op">,</tt> <tt id="link-3" class="py-name" targets="Function ottd_config.WriteConfig()=ottd_config-module.html#WriteConfig"><a title="ottd_config.WriteConfig" class="py-name" href="#" onclick="return doclink('link-3', 'WriteConfig', 'link-3');">WriteConfig</a></tt> </tt>
<a name="L4"></a><tt class="py-lineno"> 4</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt id="link-4" class="py-name" targets="Module ottd_client_event=ottd_client_event-module.html"><a title="ottd_client_event" class="py-name" href="#" onclick="return doclink('link-4', 'ottd_client_event', 'link-4');">ottd_client_event</a></tt> </tt>
<a name="L5"></a><tt class="py-lineno"> 5</tt>  <tt class="py-line"><tt class="py-keyword">from</tt> <tt id="link-5" class="py-name" targets="Module log=log-module.html"><a title="log" class="py-name" href="#" onclick="return doclink('link-5', 'log', 'link-5');">log</a></tt> <tt class="py-keyword">import</tt> <tt id="link-6" class="py-name" targets="Variable log.LOG=log-module.html#LOG,Variable ottd_client_event.LOG=ottd_client_event-module.html#LOG,Variable plugins.stats.LOG=plugins.stats-module.html#LOG,Variable webserver.LOG=webserver-module.html#LOG"><a title="log.LOG
ottd_client_event.LOG
plugins.stats.LOG
webserver.LOG" class="py-name" href="#" onclick="return doclink('link-6', 'LOG', 'link-6');">LOG</a></tt> </tt>
<a name="L6"></a><tt class="py-lineno"> 6</tt>  <tt class="py-line"><tt class="py-keyword">import</tt> <tt class="py-name">time</tt> </tt>
<a name="L7"></a><tt class="py-lineno"> 7</tt>  <tt class="py-line"> </tt>
<a name="TimeWarning"></a><div id="TimeWarning-def"><a name="L8"></a><tt class="py-lineno"> 8</tt> <a class="py-toggle" href="#" id="TimeWarning-toggle" onclick="return toggle('TimeWarning');">-</a><tt class="py-line"><tt class="py-keyword">class</tt> <a class="py-def-name" href="plugins.timewarning.TimeWarning-class.html">TimeWarning</a><tt class="py-op">(</tt><tt class="py-base-class">pluginclass</tt><tt class="py-op">.</tt><tt class="py-base-class">Plugin</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="TimeWarning-collapsed" style="display:none;" pad="++" indent="++++"></div><div id="TimeWarning-expanded"><a name="TimeWarning.init"></a><div id="TimeWarning.init-def"><a name="L9"></a><tt class="py-lineno"> 9</tt> <a class="py-toggle" href="#" id="TimeWarning.init-toggle" onclick="return toggle('TimeWarning.init');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="plugins.timewarning.TimeWarning-class.html#init">init</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="TimeWarning.init-collapsed" style="display:none;" pad="++" indent="++++++++"></div><div id="TimeWarning.init-expanded"><a name="L10"></a><tt class="py-lineno">10</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-7" class="py-name" targets="Method plugins.stats.StatsWriter.updateConfig()=plugins.stats.StatsWriter-class.html#updateConfig,Method plugins.stats.WebServer.updateConfig()=plugins.stats.WebServer-class.html#updateConfig,Method plugins.timewarning.TimeWarning.updateConfig()=plugins.timewarning.TimeWarning-class.html#updateConfig,Method plugins.webserver.StatsWriter.updateConfig()=plugins.webserver.StatsWriter-class.html#updateConfig,Method plugins.webserver.WebServer.updateConfig()=plugins.webserver.WebServer-class.html#updateConfig"><a title="plugins.stats.StatsWriter.updateConfig
plugins.stats.WebServer.updateConfig
plugins.timewarning.TimeWarning.updateConfig
plugins.webserver.StatsWriter.updateConfig
plugins.webserver.WebServer.updateConfig" class="py-name" href="#" onclick="return doclink('link-7', 'updateConfig', 'link-7');">updateConfig</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L11"></a><tt class="py-lineno">11</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">doTimeWarning</tt> <tt class="py-op">=</tt> <tt id="link-8" class="py-name"><a title="ottd_client_event.config
ottd_config.config
plugins.stats.config" class="py-name" href="#" onclick="return doclink('link-8', 'config', 'link-2');">config</a></tt><tt class="py-op">.</tt><tt class="py-name">getboolean</tt><tt class="py-op">(</tt><tt class="py-string">'timewarning'</tt><tt class="py-op">,</tt> <tt class="py-string">'warnings'</tt><tt class="py-op">)</tt> </tt>
<a name="L12"></a><tt class="py-lineno">12</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">last_timewarning</tt> <tt class="py-op">=</tt> <tt class="py-number">0</tt> </tt>
<a name="L13"></a><tt class="py-lineno">13</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-9" class="py-name" targets="Method plugins.timewarning.TimeWarning.readTimeFile()=plugins.timewarning.TimeWarning-class.html#readTimeFile"><a title="plugins.timewarning.TimeWarning.readTimeFile" class="py-name" href="#" onclick="return doclink('link-9', 'readTimeFile', 'link-9');">readTimeFile</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L14"></a><tt class="py-lineno">14</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-10" class="py-name" targets="Variable plugins.stats.StatsWriter.interval=plugins.stats.StatsWriter-class.html#interval,Variable plugins.webserver.StatsWriter.interval=plugins.webserver.StatsWriter-class.html#interval"><a title="plugins.stats.StatsWriter.interval
plugins.webserver.StatsWriter.interval" class="py-name" href="#" onclick="return doclink('link-10', 'interval', 'link-10');">interval</a></tt> <tt class="py-op">=</tt> <tt id="link-11" class="py-name"><a title="ottd_client_event.config
ottd_config.config
plugins.stats.config" class="py-name" href="#" onclick="return doclink('link-11', 'config', 'link-2');">config</a></tt><tt class="py-op">.</tt><tt class="py-name">getint</tt><tt class="py-op">(</tt><tt class="py-string">'timewarning'</tt><tt class="py-op">,</tt> <tt class="py-string">'warning_interval'</tt><tt class="py-op">)</tt> </tt>
<a name="L15"></a><tt class="py-lineno">15</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-12" class="py-name" targets="Method plugins.pluginclass.Plugin.registerCallback()=plugins.pluginclass.Plugin-class.html#registerCallback"><a title="plugins.pluginclass.Plugin.registerCallback" class="py-name" href="#" onclick="return doclink('link-12', 'registerCallback', 'link-12');">registerCallback</a></tt><tt class="py-op">(</tt><tt class="py-string">"on_mainloop"</tt><tt class="py-op">,</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-13" class="py-name" targets="Method plugins.timewarning.TimeWarning.onMainLoop()=plugins.timewarning.TimeWarning-class.html#onMainLoop"><a title="plugins.timewarning.TimeWarning.onMainLoop" class="py-name" href="#" onclick="return doclink('link-13', 'onMainLoop', 'link-13');">onMainLoop</a></tt><tt class="py-op">)</tt> </tt>
<a name="L16"></a><tt class="py-lineno">16</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-14" class="py-name" targets="Method plugins.pluginclass.Plugin.registerChatCommand()=plugins.pluginclass.Plugin-class.html#registerChatCommand"><a title="plugins.pluginclass.Plugin.registerChatCommand" class="py-name" href="#" onclick="return doclink('link-14', 'registerChatCommand', 'link-14');">registerChatCommand</a></tt><tt class="py-op">(</tt><tt class="py-string">"timeleft"</tt><tt class="py-op">,</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-15" class="py-name" targets="Method plugins.timewarning.TimeWarning.timeLeft()=plugins.timewarning.TimeWarning-class.html#timeLeft"><a title="plugins.timewarning.TimeWarning.timeLeft" class="py-name" href="#" onclick="return doclink('link-15', 'timeLeft', 'link-15');">timeLeft</a></tt><tt class="py-op">)</tt> </tt>
<a name="L17"></a><tt class="py-lineno">17</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-16" class="py-name"><a title="plugins.pluginclass.Plugin.registerChatCommand" class="py-name" href="#" onclick="return doclink('link-16', 'registerChatCommand', 'link-14');">registerChatCommand</a></tt><tt class="py-op">(</tt><tt class="py-string">"uptime"</tt><tt class="py-op">,</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-17" class="py-name" targets="Method plugins.timewarning.TimeWarning.upTime()=plugins.timewarning.TimeWarning-class.html#upTime"><a title="plugins.timewarning.TimeWarning.upTime" class="py-name" href="#" onclick="return doclink('link-17', 'upTime', 'link-17');">upTime</a></tt><tt class="py-op">)</tt> </tt>
</div><a name="L18"></a><tt class="py-lineno">18</tt>  <tt class="py-line">     </tt>
<a name="TimeWarning.timeLeft"></a><div id="TimeWarning.timeLeft-def"><a name="L19"></a><tt class="py-lineno">19</tt> <a class="py-toggle" href="#" id="TimeWarning.timeLeft-toggle" onclick="return toggle('TimeWarning.timeLeft');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="plugins.timewarning.TimeWarning-class.html#timeLeft">timeLeft</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">event</tt><tt class="py-op">,</tt> <tt class="py-param">commandstr</tt><tt class="py-op">,</tt> <tt class="py-param">recursion_depth</tt><tt class="py-op">=</tt><tt class="py-number">0</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="TimeWarning.timeLeft-collapsed" style="display:none;" pad="++" indent="++++++++"></div><div id="TimeWarning.timeLeft-expanded"><a name="L20"></a><tt class="py-lineno">20</tt>  <tt class="py-line">        <tt class="py-keyword">if</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">server_start</tt> <tt class="py-op">&gt;=</tt> <tt class="py-number">0</tt> <tt class="py-keyword">and</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">server_runtime</tt> <tt class="py-op">&gt;=</tt> <tt class="py-number">0</tt><tt class="py-op">:</tt> </tt>
<a name="L21"></a><tt class="py-lineno">21</tt>  <tt class="py-line">            <tt class="py-comment"># get time left</tt> </tt>
<a name="L22"></a><tt class="py-lineno">22</tt>  <tt class="py-line">            <tt class="py-name">tl</tt> <tt class="py-op">=</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">server_runtime</tt> <tt class="py-op">-</tt> <tt class="py-op">(</tt><tt class="py-name">time</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> <tt class="py-op">-</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">server_start</tt><tt class="py-op">)</tt> </tt>
<a name="L23"></a><tt class="py-lineno">23</tt>  <tt class="py-line">            <tt class="py-keyword">if</tt> <tt class="py-name">tl</tt> <tt class="py-op">&gt;=</tt> <tt class="py-number">86400</tt><tt class="py-op">:</tt> </tt>
<a name="L24"></a><tt class="py-lineno">24</tt>  <tt class="py-line">                <tt class="py-name">time_left</tt><tt class="py-op">=</tt><tt class="py-string">"%0.1f days"</tt><tt class="py-op">%</tt><tt class="py-op">(</tt><tt class="py-name">tl</tt><tt class="py-op">/</tt><tt class="py-number">86400.0</tt><tt class="py-op">)</tt> </tt>
<a name="L25"></a><tt class="py-lineno">25</tt>  <tt class="py-line">            <tt class="py-keyword">elif</tt> <tt class="py-name">tl</tt> <tt class="py-op">&gt;=</tt> <tt class="py-number">3600</tt><tt class="py-op">:</tt> </tt>
<a name="L26"></a><tt class="py-lineno">26</tt>  <tt class="py-line">                <tt class="py-name">time_left</tt><tt class="py-op">=</tt><tt class="py-string">"%0.1f hours"</tt><tt class="py-op">%</tt><tt class="py-op">(</tt><tt class="py-name">tl</tt><tt class="py-op">/</tt><tt class="py-number">3600.0</tt><tt class="py-op">)</tt> </tt>
<a name="L27"></a><tt class="py-lineno">27</tt>  <tt class="py-line">            <tt class="py-keyword">elif</tt> <tt class="py-name">tl</tt> <tt class="py-op">&gt;=</tt> <tt class="py-number">60</tt><tt class="py-op">:</tt> </tt>
<a name="L28"></a><tt class="py-lineno">28</tt>  <tt class="py-line">                <tt class="py-name">time_left</tt><tt class="py-op">=</tt><tt class="py-string">"%0.0f minutes"</tt><tt class="py-op">%</tt><tt class="py-op">(</tt><tt class="py-name">tl</tt><tt class="py-op">/</tt><tt class="py-number">60.0</tt><tt class="py-op">)</tt> </tt>
<a name="L29"></a><tt class="py-lineno">29</tt>  <tt class="py-line">            <tt class="py-keyword">elif</tt> <tt class="py-name">tl</tt> <tt class="py-op">&gt;</tt> <tt class="py-number">0</tt><tt class="py-op">:</tt> </tt>
<a name="L30"></a><tt class="py-lineno">30</tt>  <tt class="py-line">               <tt class="py-name">time_left</tt><tt class="py-op">=</tt><tt class="py-string">"%0.0f seconds"</tt><tt class="py-op">%</tt><tt class="py-op">(</tt><tt class="py-name">tl</tt><tt class="py-op">)</tt> </tt>
<a name="L31"></a><tt class="py-lineno">31</tt>  <tt class="py-line">            <tt class="py-keyword">elif</tt> <tt class="py-keyword">not</tt> <tt class="py-name">recursion_depth</tt> <tt class="py-op">&gt;</tt> <tt class="py-number">10</tt><tt class="py-op">:</tt> <tt class="py-comment"># don't get infinite loops</tt> </tt>
<a name="L32"></a><tt class="py-lineno">32</tt>  <tt class="py-line">                <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-18" class="py-name"><a title="plugins.timewarning.TimeWarning.readTimeFile" class="py-name" href="#" onclick="return doclink('link-18', 'readTimeFile', 'link-9');">readTimeFile</a></tt><tt class="py-op">(</tt><tt class="py-name">forcenew</tt> <tt class="py-op">=</tt> <tt class="py-name">True</tt><tt class="py-op">)</tt> </tt>
<a name="L33"></a><tt class="py-lineno">33</tt>  <tt class="py-line">                <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-19" class="py-name"><a title="plugins.timewarning.TimeWarning.timeLeft" class="py-name" href="#" onclick="return doclink('link-19', 'timeLeft', 'link-15');">timeLeft</a></tt><tt class="py-op">(</tt><tt class="py-name">event</tt><tt class="py-op">,</tt> <tt class="py-name">commandstr</tt><tt class="py-op">,</tt> <tt class="py-name">recursion_depth</tt><tt class="py-op">+</tt><tt class="py-number">1</tt><tt class="py-op">)</tt> <tt class="py-comment"># recurse</tt> </tt>
<a name="L34"></a><tt class="py-lineno">34</tt>  <tt class="py-line">                <tt class="py-keyword">return</tt> </tt>
<a name="L35"></a><tt class="py-lineno">35</tt>  <tt class="py-line">            <tt class="py-name">event</tt><tt class="py-op">.</tt><tt id="link-20" class="py-name" targets="Method ottd_client_event.IRCPrivateChat.respond()=ottd_client_event.IRCPrivateChat-class.html#respond,Method ottd_client_event.IRCPrivateNoticeChat.respond()=ottd_client_event.IRCPrivateNoticeChat-class.html#respond,Method ottd_client_event.IRCPublicChat.respond()=ottd_client_event.IRCPublicChat-class.html#respond,Method ottd_client_event.IngameChat.respond()=ottd_client_event.IngameChat-class.html#respond,Method ottd_client_event.IngameChatResponse.respond()=ottd_client_event.IngameChatResponse-class.html#respond,Method ottd_client_event.InternalCommand.respond()=ottd_client_event.InternalCommand-class.html#respond"><a title="ottd_client_event.IRCPrivateChat.respond
ottd_client_event.IRCPrivateNoticeChat.respond
ottd_client_event.IRCPublicChat.respond
ottd_client_event.IngameChat.respond
ottd_client_event.IngameChatResponse.respond
ottd_client_event.InternalCommand.respond" class="py-name" href="#" onclick="return doclink('link-20', 'respond', 'link-20');">respond</a></tt><tt class="py-op">(</tt><tt class="py-string">"time left until server will restart: %s"</tt> <tt class="py-op">%</tt> <tt class="py-name">time_left</tt><tt class="py-op">)</tt> </tt>
</div><a name="L36"></a><tt class="py-lineno">36</tt>  <tt class="py-line">             </tt>
<a name="TimeWarning.upTime"></a><div id="TimeWarning.upTime-def"><a name="L37"></a><tt class="py-lineno">37</tt> <a class="py-toggle" href="#" id="TimeWarning.upTime-toggle" onclick="return toggle('TimeWarning.upTime');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="plugins.timewarning.TimeWarning-class.html#upTime">upTime</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">event</tt><tt class="py-op">,</tt> <tt class="py-param">commandstr</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="TimeWarning.upTime-collapsed" style="display:none;" pad="++" indent="++++++++"></div><div id="TimeWarning.upTime-expanded"><a name="L38"></a><tt class="py-lineno">38</tt>  <tt class="py-line">        <tt class="py-keyword">if</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">server_start</tt> <tt class="py-op">&gt;=</tt> <tt class="py-number">0</tt><tt class="py-op">:</tt> </tt>
<a name="L39"></a><tt class="py-lineno">39</tt>  <tt class="py-line">            <tt class="py-comment"># get running time</tt> </tt>
<a name="L40"></a><tt class="py-lineno">40</tt>  <tt class="py-line">            <tt class="py-name">tl</tt> <tt class="py-op">=</tt> <tt class="py-name">time</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> <tt class="py-op">-</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">server_start</tt> </tt>
<a name="L41"></a><tt class="py-lineno">41</tt>  <tt class="py-line">            <tt class="py-keyword">if</tt> <tt class="py-name">tl</tt> <tt class="py-op">&gt;=</tt> <tt class="py-number">60</tt><tt class="py-op">*</tt><tt class="py-number">60</tt><tt class="py-op">*</tt><tt class="py-number">24</tt><tt class="py-op">:</tt> <tt class="py-comment"># 60 seconds each minute, 60 minutes each hour, 24 hours each day</tt> </tt>
<a name="L42"></a><tt class="py-lineno">42</tt>  <tt class="py-line">                <tt class="py-name">time_running</tt><tt class="py-op">=</tt><tt class="py-string">"%0.1f days"</tt><tt class="py-op">%</tt><tt class="py-op">(</tt><tt class="py-name">tl</tt><tt class="py-op">/</tt><tt class="py-number">86400.0</tt><tt class="py-op">)</tt> </tt>
<a name="L43"></a><tt class="py-lineno">43</tt>  <tt class="py-line">            <tt class="py-keyword">elif</tt> <tt class="py-name">tl</tt> <tt class="py-op">&gt;=</tt> <tt class="py-number">60</tt><tt class="py-op">*</tt><tt class="py-number">60</tt><tt class="py-op">:</tt>  <tt class="py-comment"># 60 seconds each minute, 60 minutes each hour</tt> </tt>
<a name="L44"></a><tt class="py-lineno">44</tt>  <tt class="py-line">                <tt class="py-name">time_running</tt><tt class="py-op">=</tt><tt class="py-string">"%0.1f hours"</tt><tt class="py-op">%</tt><tt class="py-op">(</tt><tt class="py-name">tl</tt><tt class="py-op">/</tt><tt class="py-number">3600.0</tt><tt class="py-op">)</tt> </tt>
<a name="L45"></a><tt class="py-lineno">45</tt>  <tt class="py-line">            <tt class="py-keyword">elif</tt> <tt class="py-name">tl</tt> <tt class="py-op">&gt;=</tt> <tt class="py-number">60</tt><tt class="py-op">:</tt>     <tt class="py-comment"># 60 seconds each minute</tt> </tt>
<a name="L46"></a><tt class="py-lineno">46</tt>  <tt class="py-line">                <tt class="py-name">time_running</tt><tt class="py-op">=</tt><tt class="py-string">"%0.0f minutes"</tt><tt class="py-op">%</tt><tt class="py-op">(</tt><tt class="py-name">tl</tt><tt class="py-op">/</tt><tt class="py-number">60.0</tt><tt class="py-op">)</tt> </tt>
<a name="L47"></a><tt class="py-lineno">47</tt>  <tt class="py-line">            <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
<a name="L48"></a><tt class="py-lineno">48</tt>  <tt class="py-line">                <tt class="py-name">time_running</tt><tt class="py-op">=</tt><tt class="py-string">"%0.0f seconds"</tt><tt class="py-op">%</tt><tt class="py-op">(</tt><tt class="py-name">tl</tt><tt class="py-op">)</tt> </tt>
<a name="L49"></a><tt class="py-lineno">49</tt>  <tt class="py-line">            <tt class="py-name">event</tt><tt class="py-op">.</tt><tt id="link-21" class="py-name"><a title="ottd_client_event.IRCPrivateChat.respond
ottd_client_event.IRCPrivateNoticeChat.respond
ottd_client_event.IRCPublicChat.respond
ottd_client_event.IngameChat.respond
ottd_client_event.IngameChatResponse.respond
ottd_client_event.InternalCommand.respond" class="py-name" href="#" onclick="return doclink('link-21', 'respond', 'link-20');">respond</a></tt><tt class="py-op">(</tt><tt class="py-name">time_running</tt><tt class="py-op">)</tt> </tt>
</div><a name="TimeWarning.updateConfig"></a><div id="TimeWarning.updateConfig-def"><a name="L50"></a><tt class="py-lineno">50</tt> <a class="py-toggle" href="#" id="TimeWarning.updateConfig-toggle" onclick="return toggle('TimeWarning.updateConfig');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="plugins.timewarning.TimeWarning-class.html#updateConfig">updateConfig</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="TimeWarning.updateConfig-collapsed" style="display:none;" pad="++" indent="++++++++"></div><div id="TimeWarning.updateConfig-expanded"><a name="L51"></a><tt class="py-lineno">51</tt>  <tt class="py-line">        <tt class="py-name">configchanged</tt> <tt class="py-op">=</tt> <tt class="py-name">False</tt> </tt>
<a name="L52"></a><tt class="py-lineno">52</tt>  <tt class="py-line">        <tt class="py-keyword">if</tt> <tt class="py-keyword">not</tt> <tt id="link-22" class="py-name"><a title="ottd_client_event.config
ottd_config.config
plugins.stats.config" class="py-name" href="#" onclick="return doclink('link-22', 'config', 'link-2');">config</a></tt><tt class="py-op">.</tt><tt class="py-name">has_section</tt><tt class="py-op">(</tt><tt class="py-string">"timewarning"</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L53"></a><tt class="py-lineno">53</tt>  <tt class="py-line">            <tt id="link-23" class="py-name"><a title="ottd_client_event.config
ottd_config.config
plugins.stats.config" class="py-name" href="#" onclick="return doclink('link-23', 'config', 'link-2');">config</a></tt><tt class="py-op">.</tt><tt class="py-name">add_section</tt><tt class="py-op">(</tt><tt class="py-string">"timewarning"</tt><tt class="py-op">)</tt> </tt>
<a name="L54"></a><tt class="py-lineno">54</tt>  <tt class="py-line">            <tt class="py-name">configchanged</tt> <tt class="py-op">=</tt> <tt class="py-name">True</tt> </tt>
<a name="L55"></a><tt class="py-lineno">55</tt>  <tt class="py-line">        <tt class="py-name">options</tt> <tt class="py-op">=</tt> <tt class="py-op">{</tt> </tt>
<a name="L56"></a><tt class="py-lineno">56</tt>  <tt class="py-line">            <tt class="py-string">"enable"</tt><tt class="py-op">:</tt><tt class="py-string">"On"</tt><tt class="py-op">,</tt> </tt>
<a name="L57"></a><tt class="py-lineno">57</tt>  <tt class="py-line">            <tt class="py-string">"starttimefile"</tt><tt class="py-op">:</tt><tt class="py-string">"starttime.txt"</tt><tt class="py-op">,</tt> </tt>
<a name="L58"></a><tt class="py-lineno">58</tt>  <tt class="py-line">            <tt class="py-string">"time_running"</tt><tt class="py-op">:</tt><tt class="py-string">"604800"</tt><tt class="py-op">,</tt> </tt>
<a name="L59"></a><tt class="py-lineno">59</tt>  <tt class="py-line">            <tt class="py-string">"warnings"</tt><tt class="py-op">:</tt><tt class="py-string">"On"</tt><tt class="py-op">,</tt> </tt>
<a name="L60"></a><tt class="py-lineno">60</tt>  <tt class="py-line">            <tt class="py-string">"warning_interval"</tt><tt class="py-op">:</tt><tt class="py-string">"21600"</tt> </tt>
<a name="L61"></a><tt class="py-lineno">61</tt>  <tt class="py-line">        <tt class="py-op">}</tt> </tt>
<a name="L62"></a><tt class="py-lineno">62</tt>  <tt class="py-line">        <tt class="py-keyword">for</tt> <tt class="py-name">option</tt> <tt class="py-keyword">in</tt> <tt class="py-name">options</tt><tt class="py-op">:</tt>  </tt>
<a name="L63"></a><tt class="py-lineno">63</tt>  <tt class="py-line">            <tt class="py-keyword">if</tt> <tt class="py-keyword">not</tt> <tt id="link-24" class="py-name"><a title="ottd_client_event.config
ottd_config.config
plugins.stats.config" class="py-name" href="#" onclick="return doclink('link-24', 'config', 'link-2');">config</a></tt><tt class="py-op">.</tt><tt class="py-name">has_option</tt><tt class="py-op">(</tt><tt class="py-string">"timewarning"</tt><tt class="py-op">,</tt> <tt class="py-name">option</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
<a name="L64"></a><tt class="py-lineno">64</tt>  <tt class="py-line">                <tt id="link-25" class="py-name"><a title="ottd_client_event.config
ottd_config.config
plugins.stats.config" class="py-name" href="#" onclick="return doclink('link-25', 'config', 'link-2');">config</a></tt><tt class="py-op">.</tt><tt class="py-name">set</tt><tt class="py-op">(</tt><tt class="py-string">"timewarning"</tt><tt class="py-op">,</tt> <tt class="py-name">option</tt><tt class="py-op">,</tt> <tt class="py-name">options</tt><tt class="py-op">[</tt><tt class="py-name">option</tt><tt class="py-op">]</tt><tt class="py-op">)</tt> </tt>
<a name="L65"></a><tt class="py-lineno">65</tt>  <tt class="py-line">                <tt class="py-name">configchanged</tt> <tt class="py-op">=</tt> <tt class="py-name">True</tt> </tt>
<a name="L66"></a><tt class="py-lineno">66</tt>  <tt class="py-line">        <tt class="py-keyword">if</tt> <tt class="py-name">configchanged</tt><tt class="py-op">:</tt> </tt>
<a name="L67"></a><tt class="py-lineno">67</tt>  <tt class="py-line">            <tt id="link-26" class="py-name"><a title="ottd_config.WriteConfig" class="py-name" href="#" onclick="return doclink('link-26', 'WriteConfig', 'link-3');">WriteConfig</a></tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
</div><a name="L68"></a><tt class="py-lineno">68</tt>  <tt class="py-line">     </tt>
<a name="TimeWarning.onMainLoop"></a><div id="TimeWarning.onMainLoop-def"><a name="L69"></a><tt class="py-lineno">69</tt> <a class="py-toggle" href="#" id="TimeWarning.onMainLoop-toggle" onclick="return toggle('TimeWarning.onMainLoop');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="plugins.timewarning.TimeWarning-class.html#onMainLoop">onMainLoop</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="TimeWarning.onMainLoop-collapsed" style="display:none;" pad="++" indent="++++++++"></div><div id="TimeWarning.onMainLoop-expanded"><a name="L70"></a><tt class="py-lineno">70</tt>  <tt class="py-line">        <tt class="py-keyword">if</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">doTimeWarning</tt> <tt class="py-keyword">and</tt> <tt class="py-name">time</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> <tt class="py-op">-</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">last_timewarning</tt> <tt class="py-op">&gt;</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-27" class="py-name"><a title="plugins.stats.StatsWriter.interval
plugins.webserver.StatsWriter.interval" class="py-name" href="#" onclick="return doclink('link-27', 'interval', 'link-10');">interval</a></tt><tt class="py-op">:</tt> </tt>
<a name="L71"></a><tt class="py-lineno">71</tt>  <tt class="py-line">            <tt id="link-28" class="py-name"><a title="ottd_client_event" class="py-name" href="#" onclick="return doclink('link-28', 'ottd_client_event', 'link-4');">ottd_client_event</a></tt><tt class="py-op">.</tt><tt id="link-29" class="py-name" targets="Class ottd_client_event.InternalCommand=ottd_client_event.InternalCommand-class.html"><a title="ottd_client_event.InternalCommand" class="py-name" href="#" onclick="return doclink('link-29', 'InternalCommand', 'link-29');">InternalCommand</a></tt><tt class="py-op">(</tt><tt class="py-string">"timeleft"</tt><tt class="py-op">,</tt> <tt class="py-name">self</tt><tt class="py-op">.</tt><tt id="link-30" class="py-name" targets="Module openttd.client=openttd.client-module.html"><a title="openttd.client" class="py-name" href="#" onclick="return doclink('link-30', 'client', 'link-30');">client</a></tt><tt class="py-op">)</tt> </tt>
<a name="L72"></a><tt class="py-lineno">72</tt>  <tt class="py-line">            <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">last_timewarning</tt> <tt class="py-op">=</tt> <tt class="py-name">time</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
</div><a name="L73"></a><tt class="py-lineno">73</tt>  <tt class="py-line">         </tt>
<a name="TimeWarning.readTimeFile"></a><div id="TimeWarning.readTimeFile-def"><a name="L74"></a><tt class="py-lineno">74</tt> <a class="py-toggle" href="#" id="TimeWarning.readTimeFile-toggle" onclick="return toggle('TimeWarning.readTimeFile');">-</a><tt class="py-line">    <tt class="py-keyword">def</tt> <a class="py-def-name" href="plugins.timewarning.TimeWarning-class.html#readTimeFile">readTimeFile</a><tt class="py-op">(</tt><tt class="py-param">self</tt><tt class="py-op">,</tt> <tt class="py-param">forcenew</tt><tt class="py-op">=</tt><tt class="py-name">False</tt><tt class="py-op">)</tt><tt class="py-op">:</tt> </tt>
</div><div id="TimeWarning.readTimeFile-collapsed" style="display:none;" pad="++" indent="++++++++"></div><div id="TimeWarning.readTimeFile-expanded"><a name="L75"></a><tt class="py-lineno">75</tt>  <tt class="py-line">        <tt class="py-name">timestr</tt> <tt class="py-op">=</tt> <tt class="py-string">''</tt> </tt>
<a name="L76"></a><tt class="py-lineno">76</tt>  <tt class="py-line">        <tt class="py-keyword">try</tt><tt class="py-op">:</tt> </tt>
<a name="L77"></a><tt class="py-lineno">77</tt>  <tt class="py-line">            <tt class="py-name">f</tt> <tt class="py-op">=</tt> <tt class="py-name">open</tt><tt class="py-op">(</tt><tt id="link-31" class="py-name"><a title="ottd_client_event.config
ottd_config.config
plugins.stats.config" class="py-name" href="#" onclick="return doclink('link-31', 'config', 'link-2');">config</a></tt><tt class="py-op">.</tt><tt class="py-name">get</tt><tt class="py-op">(</tt><tt class="py-string">'timewarning'</tt><tt class="py-op">,</tt> <tt class="py-string">'starttimefile'</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> <tt class="py-string">'r'</tt><tt class="py-op">)</tt> </tt>
<a name="L78"></a><tt class="py-lineno">78</tt>  <tt class="py-line">            <tt class="py-name">timestr</tt> <tt class="py-op">=</tt> <tt class="py-name">f</tt><tt class="py-op">.</tt><tt class="py-name">read</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L79"></a><tt class="py-lineno">79</tt>  <tt class="py-line">            <tt class="py-name">f</tt><tt class="py-op">.</tt><tt class="py-name">close</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L80"></a><tt class="py-lineno">80</tt>  <tt class="py-line">        <tt class="py-keyword">except</tt><tt class="py-op">:</tt> </tt>
<a name="L81"></a><tt class="py-lineno">81</tt>  <tt class="py-line">            <tt id="link-32" class="py-name"><a title="log.LOG
ottd_client_event.LOG
plugins.stats.LOG
webserver.LOG" class="py-name" href="#" onclick="return doclink('link-32', 'LOG', 'link-6');">LOG</a></tt><tt class="py-op">.</tt><tt id="link-33" class="py-name" targets="Class sstruct.error=sstruct.error-class.html"><a title="sstruct.error" class="py-name" href="#" onclick="return doclink('link-33', 'error', 'link-33');">error</a></tt><tt class="py-op">(</tt><tt class="py-string">"error while reading starttimefile"</tt><tt class="py-op">)</tt> </tt>
<a name="L82"></a><tt class="py-lineno">82</tt>  <tt class="py-line">        <tt class="py-keyword">if</tt> <tt class="py-name">timestr</tt> <tt class="py-op">!=</tt> <tt class="py-string">''</tt> <tt class="py-keyword">and</tt> <tt class="py-keyword">not</tt> <tt class="py-name">forcenew</tt><tt class="py-op">:</tt> </tt>
<a name="L83"></a><tt class="py-lineno">83</tt>  <tt class="py-line">            <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">server_start</tt> <tt class="py-op">=</tt> <tt class="py-name">int</tt><tt class="py-op">(</tt><tt class="py-name">timestr</tt><tt class="py-op">.</tt><tt class="py-name">strip</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<a name="L84"></a><tt class="py-lineno">84</tt>  <tt class="py-line">        <tt class="py-keyword">else</tt><tt class="py-op">:</tt> </tt>
<a name="L85"></a><tt class="py-lineno">85</tt>  <tt class="py-line">            <tt class="py-name">f</tt> <tt class="py-op">=</tt> <tt class="py-name">open</tt><tt class="py-op">(</tt><tt id="link-34" class="py-name"><a title="ottd_client_event.config
ottd_config.config
plugins.stats.config" class="py-name" href="#" onclick="return doclink('link-34', 'config', 'link-2');">config</a></tt><tt class="py-op">.</tt><tt class="py-name">get</tt><tt class="py-op">(</tt><tt class="py-string">'timewarning'</tt><tt class="py-op">,</tt> <tt class="py-string">'starttimefile'</tt><tt class="py-op">)</tt><tt class="py-op">,</tt> <tt class="py-string">'wb'</tt><tt class="py-op">)</tt> </tt>
<a name="L86"></a><tt class="py-lineno">86</tt>  <tt class="py-line">            <tt class="py-name">f</tt><tt class="py-op">.</tt><tt class="py-name">write</tt><tt class="py-op">(</tt><tt class="py-name">str</tt><tt class="py-op">(</tt><tt class="py-name">int</tt><tt class="py-op">(</tt><tt class="py-name">time</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<a name="L87"></a><tt class="py-lineno">87</tt>  <tt class="py-line">            <tt class="py-name">f</tt><tt class="py-op">.</tt><tt class="py-name">close</tt><tt class="py-op">(</tt><tt class="py-op">)</tt> </tt>
<a name="L88"></a><tt class="py-lineno">88</tt>  <tt class="py-line">            <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">server_start</tt> <tt class="py-op">=</tt> <tt class="py-name">int</tt><tt class="py-op">(</tt><tt class="py-name">time</tt><tt class="py-op">.</tt><tt class="py-name">time</tt><tt class="py-op">(</tt><tt class="py-op">)</tt><tt class="py-op">)</tt> </tt>
<a name="L89"></a><tt class="py-lineno">89</tt>  <tt class="py-line">        <tt class="py-name">self</tt><tt class="py-op">.</tt><tt class="py-name">server_runtime</tt> <tt class="py-op">=</tt> <tt id="link-35" class="py-name"><a title="ottd_client_event.config
ottd_config.config
plugins.stats.config" class="py-name" href="#" onclick="return doclink('link-35', 'config', 'link-2');">config</a></tt><tt class="py-op">.</tt><tt class="py-name">getint</tt><tt class="py-op">(</tt><tt class="py-string">'timewarning'</tt><tt class="py-op">,</tt> <tt class="py-string">'time_running'</tt><tt class="py-op">)</tt> </tt>
</div></div><a name="L90"></a><tt class="py-lineno">90</tt>  <tt class="py-line"> </tt><script type="text/javascript">
<!--
expandto(location.href);
// -->
</script>
</pre>
<br />
<!-- ==================== NAVIGATION BAR ==================== -->
<table class="navbar" border="0" width="100%" cellpadding="0"
       bgcolor="#a0c0ff" cellspacing="0">
  <tr valign="middle">

  <!-- Tree link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="module-tree.html">Trees</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Index link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="identifier-index.html">Indices</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Help link -->
      <th>&nbsp;&nbsp;&nbsp;<a
        href="help.html">Help</a>&nbsp;&nbsp;&nbsp;</th>

  <!-- Project homepage -->
      <th class="navbar" align="right" width="100%">
        <table border="0" cellpadding="0" cellspacing="0">
          <tr><th class="navbar" align="center"
            ><a class="navbar" target="_top" href="http://openttd-python.googlecode.com">OpenTTD-Python</a></th>
          </tr></table></th>
  </tr>
</table>
<table border="0" cellpadding="0" cellspacing="0" width="100%%">
  <tr>
    <td align="left" class="footer">
    Generated by Epydoc 3.0.1 on Mon Oct 20 13:03:13 2008
    </td>
    <td align="right" class="footer">
      <a target="mainFrame" href="http://epydoc.sourceforge.net"
        >http://epydoc.sourceforge.net</a>
    </td>
  </tr>
</table>

<script type="text/javascript">
  <!--
  // Private objects are initially displayed (because if
  // javascript is turned off then we want them to be
  // visible); but by default, we want to hide them.  So hide
  // them unless we have a cookie that says to show them.
  checkCookie();
  // -->
</script>
</body>
</html>
